package com.yunyao.dao.service.bamu.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunyao.common.constant.enums.DataDeletedStatus;
import com.yunyao.dao.mapper.BamuSpReconciliationSettlementMapper;
import com.yunyao.dao.model.BamuSpReconciliationSettlement;
import com.yunyao.dao.model.BamuSupplyApply;
import com.yunyao.dao.service.bamu.IBamuSpReconciliationSettlementService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 供应商结算对账表 服务实现类
 * </p>
 *
 * @author xingjishuai
 * @since 2024-07-02
 */
@Service
public class BamuSpReconciliationSettlementServiceImpl extends ServiceImpl<BamuSpReconciliationSettlementMapper, BamuSpReconciliationSettlement> implements IBamuSpReconciliationSettlementService {

    /**
     * 根据ID和删除状态查询BamuSpReconciliationSettlement实体
     * 此方法专注于查询未被逻辑删除的实体，以确保只处理有效的数据
     *
     * @param id 实体的唯一标识符
     * @return 如果找到未被逻辑删除且匹配给定ID的实体，则返回该实体；否则返回null
     */
    @Override
    public BamuSpReconciliationSettlement getByIdAndDeleted(String id) {
        // 创建查询包装器并设置查询条件：isDeleted为未删除且ID匹配
        LambdaQueryWrapper<BamuSpReconciliationSettlement> queryWrapper =
                new LambdaQueryWrapper<BamuSpReconciliationSettlement>()
                        .eq(BamuSpReconciliationSettlement::getIsDeleted,
                                DataDeletedStatus.NO.getType()).eq(BamuSpReconciliationSettlement::getId, id);
        // 执行查询并返回结果
        return getOne(queryWrapper);
    }

    @Override
    public List<BamuSpReconciliationSettlement> listById(String Id) {
        // 检查合同ID是否为空或空白，如果是，则返回一个空列表
        if (org.apache.commons.lang3.StringUtils.isBlank(Id)) {
            return List.of();
        }
        // 创建一个LambdaQueryWrapper用于构建查询条件
        LambdaQueryWrapper<BamuSpReconciliationSettlement> wrapper =
                new LambdaQueryWrapper<BamuSpReconciliationSettlement>().eq(BamuSpReconciliationSettlement::getId,
                        Id).eq(BamuSpReconciliationSettlement::getIsDeleted, DataDeletedStatus.NO.getType());
        // 使用构建的查询条件获取并返回关联的材料列表
        return list(wrapper);
    }
}
